import 'package:distribution_mall_flutter/constant/cf_constant.dart';
import 'package:distribution_mall_flutter/constant/status_constant.dart';
import 'package:distribution_mall_flutter/entity/order/detail/order_detail_entity.dart';
import 'package:distribution_mall_flutter/generated/l10n.dart';
import 'package:distribution_mall_flutter/provider/order/order_detail.dart';
import 'package:distribution_mall_flutter/utils/utils.dart';
import 'package:distribution_mall_flutter/widgets/card.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class OrderNum extends ConsumerWidget {
  const OrderNum({super.key});

  Widget listRender(
      {required String leftText,
      required String rightText,
      bool showDis = false,
      bool showOther = false}) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: EdgeConstant.edge5),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            leftText,
            style: const TextStyle(
                color: ColorConstant.grey153, fontSize: FontConstant.f14),
          ),
          Row(
            children: [
              Text(
                rightText,
                style: const TextStyle(
                    color: ColorConstant.black51, fontSize: FontConstant.f12),
              ),
              Visibility(
                visible: showOther,
                child: Row(
                  children: [
                    Container(
                      width: 1,
                      height: 15,
                      margin: const EdgeInsets.symmetric(
                          horizontal: EdgeConstant.edge10),
                      color: ColorConstant.grey114,
                      child: const SizedBox.shrink(),
                    ),
                    GestureDetector(
                        onTap: () {
                          Utils.copy(rightText);
                        },
                        child: Text(
                          S.current.copy,
                          style: const TextStyle(
                              fontSize: FontConstant.f12,
                              color: Color.fromRGBO(22, 119, 255, 1)),
                        ))
                  ],
                ),
              )
            ],
          )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final orderModal = ref.watch(orderDetailProvider);
    return EPCard(
      margin: const EdgeInsets.fromLTRB(
          EdgeConstant.edge10, EdgeConstant.edge10, EdgeConstant.edge10, 0),
      padding: const EdgeInsets.all(
        EdgeConstant.edge10,
      ),
      child: Column(
        children: [
          listRender(
              showOther: true,
              leftText: S.of(context).order_number,
              rightText: orderModal.detal?.distributionOrderId ?? ''),
          Visibility(
              visible: orderModal.paymentId.isNotEmpty,
              child: listRender(
                  leftText: S.of(context).order_oayment_number,
                  rightText: orderModal.paymentId)),
          listRender(
              leftText: S.of(context).order_time,
              rightText: Utils.getTime(orderModal.detal?.gmtCreate))
        ],
      ),
    );
  }
}
